/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package torpedo_server.threads;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;
import torpedo_server.PlayerHandlerThread;
import torpedo_server.messages.Message;

/**
 *
 * @author hengi
 */
public class Player1Thread extends Thread {
    private Socket sock;

    public Player1Thread(Socket soc) {
        this.sock=soc;
    }
    @Override
    public void run(){
        Message mes = this.getMessage();
        if(mes.getType().equals("StartBattleMessage")){
            PlayerHandlerThread.ready1=true;
            System.out.println("Player1 Ready");
        }
        
    }
    public Message getMessage(){
      
        
        ObjectInputStream ios=null;
        try {
            ios = new ObjectInputStream(this.sock.getInputStream());
        } catch (IOException ex) {
            Logger.getLogger(Player1Thread.class.getName()).log(Level.SEVERE, null, ex);
        }
        Message message=null;
        try {
            message = (Message)ios.readObject();
        } catch (IOException ex) {
            Logger.getLogger(Player1Thread.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Player1Thread.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        return  message;
    }
    
    public void SendMess(Message mess) throws IOException{
       OutputStream os = this.sock.getOutputStream();
       ObjectOutputStream oos = new ObjectOutputStream(os);
       oos.writeObject(mess);
       oos.flush();

        
    }
    
    
    
}

